
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Csla;
using Csla.Data;
using Csla.Validation;
using System.Collections;
using HousingInfo.DataLinQ;

namespace HousingInfo.Library
{ 
	[Serializable()] 
	public class SubTopicForumInfo : Csla.NameValueListBase<int?, string>
	{

		#region Factory Methods
		private SubTopicForumInfo()
		{ /* require use of factory method */ }

		private static SubTopicForumInfo list;

		public static SubTopicForumInfo GetSubTopicForumInfo()
		{
			//if (list == null)
			list = DataPortal.Fetch<SubTopicForumInfo>();
			return list;
		}

		public static void InvalidateCache()
		{
			list = null;
		}
		#endregion //Factory Methods

		#region Data Access
		/// <summary>
        /// Execute Fetch object. Method will be call with same type object paramater.
        /// </summary>
        /// <param name="criteria"></param>
        private void DataPortal_Fetch()
        {
           using (var mgr = ContextManager<HousingInfo.DataLinQ.HousingInfoDataContext>
						.GetManager(Database.HousingInfoConnection))
			{
				RaiseListChangedEvents = false;
				IsReadOnly = false;
				
				this.AddRange(
					from row in mgr.DataContext.SubTopicForums
                    where row.IsActive == true
					select (new NameValuePair(row.SubTopicForumID, row.SubTopicForumName))
				);
				
				IsReadOnly = true;
				RaiseListChangedEvents = true;
			}//using
        }
	    #endregion //Data Access



        #region Trang Admin - Lay danh muc con theo danh muc cha

        #region Ham Lay danh sach danh muc con theo danh muc cha
        public static SubTopicForumInfo GetSubTopicForumInfo_ByIDParrent(int parrentID, bool isactive)
        {
            return DataPortal.Fetch<SubTopicForumInfo>(new FilterCriteriaSubTopicForumInfo_ByIDParrent(parrentID, isactive));
        }
        #endregion //End ham lay tung loai danh muc

        #region khai bao tham so
        private class FilterCriteriaSubTopicForumInfo_ByIDParrent
        {
            public int idparrent;
            public bool active;
            public FilterCriteriaSubTopicForumInfo_ByIDParrent(int id, bool at)
            {
                this.idparrent = id;
                this.active = at;
            }
        }
        #endregion//end khai bao tham so

        #region Truy cap du lieu
        private void DataPortal_Fetch(FilterCriteriaSubTopicForumInfo_ByIDParrent parram)
        {
            using (var mgr = ContextManager<HousingInfo.DataLinQ.HousingInfoDataContext>
                        .GetManager(Database.HousingInfoConnection))
            {
                RaiseListChangedEvents = false;
                IsReadOnly = false;
                if (parram.active == true)
                {
                    this.AddRange(
                        from row in mgr.DataContext.SubTopicForums
                        where row.IsActive == true && row.CategoryID == parram.idparrent
                        select (new NameValuePair(row.SubTopicForumID, row.SubTopicForumName))
                    );
                }
                else
                {
                    this.AddRange(
                        from row in mgr.DataContext.SubTopicForums
                        where row.CategoryID == parram.idparrent
                        select (new NameValuePair(row.SubTopicForumID, row.SubTopicForumName))
                    );
                }

                IsReadOnly = true;
                RaiseListChangedEvents = true;
            }//using
        }
        #endregion//end truy cap

        #endregion //

	}
}

